package message

import (
	"gomonitor-server/src/mylog"
	"gomonitor-server/src/tcp/types"
	"net"
	"os"
)

func HelloMessage(messageHandler *MessageHandler, data []byte, conn net.Conn) {
	host, port, err := net.SplitHostPort(conn.RemoteAddr().String())
	if err != nil {
		mylog.Logger.Error("error reading from tcp: ", err)
		return
	}
	mylog.Logger.Infof("接收到%s:%s 的消息:%s", host, port, string(data))
	hostname, err := os.Hostname()
	if err != nil {
		mylog.Logger.Error("error reading from tcp: ", err)
		return
	}
	messageHandler.SendMessage(types.MSG_FROM_SERVER, []byte(hostname), types.MSG_TYPE_CONNECT, conn)
}
